package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.Widget;

public class Toolbar extends HorizontalPanel {
  public HorizontalPanel inner;

  public Toolbar() {
    super();
    inner = new HorizontalPanel();
    add(inner);
    setWidth("100%");
    setStyleName("jdgwt-toolbar");
  }

  public void add(ToolButton button) {
    inner.add(button);
    inner.setCellVerticalAlignment(button, HorizontalPanel.ALIGN_BOTTOM);
  }

  public void remove(ToolButton button) {
    inner.remove(button);
  }

  public ToolButton addSplit() {
    ToolButton button = new ToolButton("|");
    button.setStyleName("button");
    add(button);
    return button;
  }

  public ToolButton addButton(String image, String title, ClickListener listener) {
    ToolButton button = new ToolButton("&nbsp;<image src='images/" + image + "'/>" + title
        + "&nbsp;");
    button.setTitle(title);
    button.setStyleName("button");
    if (listener != null)
      button.addClickListener(listener);
    add(button);
    return button;
  }

  public ToolButton addFilterButton(ClickListener listener) {
    return addButton("filter.gif", "筛选", listener);
  }

  public ToolButton addListButton(ClickListener listener) {
    return addButton("gridview.gif", "列表", listener);
  }

  public ToolButton addViewButton(ClickListener listener) {
    return addButton("view.gif", "查看", listener);
  }

  public ToolButton addNewButton(ClickListener listener) {
    return addButton("newitem.gif", "新增", listener);
  }

  public ToolButton addEditButton(ClickListener listener) {
    return addButton("edititem.gif", "编辑", listener);
  }

  public ToolButton addSaveButton(ClickListener listener) {
    return addButton("saveitem.gif", "保存", listener);
  }

  public ToolButton addDeleteButton(ClickListener listener) {
    return addButton("delitem.gif", "删除", listener);
  }

  public ToolButton addBatchDeleteButton(ClickListener listener) {
    return addButton("delitem-batch.gif", "批量删除", listener);
  }

  public ToolButton addCancelButton(ClickListener listener) {
    return addButton("cancel.gif", "取消", listener);
  }

  public ToolButton addAuditButton(ClickListener listener) {
    return addButton("audit.gif", "审核", listener);
  }

  public ToolButton addBatchAuditButton(ClickListener listener) {
    return addButton("audit-batch.gif", "批量审核", listener);
  }

  public ToolButton addNewLineButton(ClickListener listener) {
    return addButton("newline.gif", "添加行", listener);
  }

  public ToolButton addDeleteLineButton(ClickListener listener) {
    return addButton("delline.gif", "删除行", listener);
  }

  public ToolButton addReceiveButton(ClickListener listener) {
    return addButton("receive.gif", "收货", listener);
  }

  public ToolButton addDeliverButton(ClickListener listener) {
    return addButton("deliver.gif", "发货", listener);
  }

  public ToolButton addCeaseButton(ClickListener listener) {
    return addButton("cease.gif", "中止", listener);
  }

  public ToolButton addSubmitButton(ClickListener listener) {
    return addButton("submit.gif", "提交", listener);
  }

  public ToolButton addBatchSubmitButton(ClickListener listener) {
    return addButton("submit.gif", "批量提交", listener);
  }

  public ToolButton addConfirmButton(ClickListener listener) {
    return addButton("submit.gif", "批准", listener);
  }

  public ToolButton addBatchConfirmButton(ClickListener listener) {
    return addButton("submit.gif", "批量批准", listener);
  }

  public ToolButton addCancelConfirmButton(ClickListener listener) {
    return addButton("cancel.gif", "取消批准", listener);
  }

  public ToolButton addRefuseButton(ClickListener listener) {
    return addButton("submit.gif", "拒绝", listener);
  }

  public static class ToolButton extends HTML implements MouseListener {
    public ToolButton() {
      super();
      init();
    }

    public ToolButton(String html) {
      super(html);
      init();
    }

    public void init() {
      addMouseListener(this);
    }

    public void onMouseDown(Widget sender, int x, int y) {
      sender.setStyleName("button");
    }

    public void onMouseEnter(Widget sender) {
      sender.setStyleName("button-enter");
    }

    public void onMouseLeave(Widget sender) {
      sender.setStyleName("button");
    }

    public void onMouseMove(Widget sender, int x, int y) {
    }

    public void onMouseUp(Widget sender, int x, int y) {
    }

  }
}
